<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/head.ftl"/>
    <script>
        $(function () {
            //弹出模态框并回显里面的数据
            $(".changeBtn").click(function () {
                $("#editForm").clearForm();

                var json = $(this).data("json");
                if (json) {
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='travel.id']").val(json.travelId);
                    $("#editForm input[name='title']").val(json.title);
                    $("#editForm input[name='subTitle']").val(json.subTitle);
                    $("#editForm img").attr("src", json.coverUrl);
                    $("#editForm input[name='coverUrl']").val(json.coverUrl);
                    $("#editForm input[name='schedule']").val(json.schedule);
                    $("#editForm select[name='type']").val(json.type);
                    $("#skip").attr("href", $("#skip").data("href") + json.travelId);
                }
                $("#inputModal").modal("show");
            })


            //保存操作
            $("#save").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if (data.success) {
                        window.location.reload();
                    } else {
                        $.messager.alert("温馨提示", data.msg);
                    }
                })
            });
        });
    </script>

    <#--模态框里面的样式-->
    <style>
        #showContentModal img {
            width: 100%;
        }

        #showContentModal .modal-body {
            max-height: 500px;
        /*/ / 最大高度*/ overflow-y: auto;
        /*/ / 超过最大高度, 自动滚动*/
        }
    </style>

</head>
<body>


<!-- 模态框（Modal） -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑/添加</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <input type="hidden" name="travel.id"/>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img src="#" width="60px">
                            <input type="hidden" class="form-control" name="coverUrl">
                            <input type="file" class="form-control" name="pic">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="type">
                                <option value="1">周推荐</option>
                                <option value="2">月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a data-href="/travel/releaseList.do?travelId=" target="_blank" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-save" id="save">保存</button>
            </div>
        </div>
    </div>
</div>


<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#assign menu="travelCommend"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题">
                </div>

                <div class="form-group">
                    <select class="form-control" name="type"">
                    <option value="-1">全部</option>
                    <option value="1">周推荐</option>
                    <option value="2">月推荐</option>
                    <option value="3">攻略推荐</option>
                    </select>
                    <script>
                        $("#searchForm select[name='type']").val(${qo.type});
                    </script>
                </div>

                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
            </form>


            <table class="table table-striped table-hover">
                <tr>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td><img src="${(entity.coverUrl)!}" width="30px"></td>
                        <td>${(entity.title)!}</td>
                        <td>${(entity.subTitle)!}</td>
                        <td>${(entity.schedule?string("yyyy-MM-dd"))!}</td>
                        <td>${(entity.getTypename())!}</td>
                        <td><a href="javascript:;" class="changeBtn" data-json='${entity.jsonString}'>修改</a></td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


</body>
</html>